package org.gd136.ce.script.impl;

import org.gd136.ce.script.Script;
import org.gd136.ce.script.ScriptStage;

public class AddScript extends Script {

	private static final String TAG = "#add ";

	private String paramName;
	private String value;

	@Override
	public Script readScript(String scriptLine) {
		AddScript as = null;
		if (scriptLine.startsWith(TAG)) {
			as = new AddScript();
			String part = scriptLine.substring(TAG.length());
			int p = part.indexOf(' ');
			if (p < 1) {
				throw new IllegalArgumentException("add 格式不正确! file[" + fileName
						+ "] line[" + lineNum + "]");
			}
			as.paramName = part.substring(0, p);
			as.value = part.substring(p + 1);
			as.addToPoolAndLinkFrontScript();
		}
		return as;
	}

	@Override
	public void execute(ScriptStage stage) {
		stage.addVariable(paramName, value);
	}

}
